home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rjs.lha / RJS / Transport / src / InetSocket.C < prev    next >
C/C++ Source or Header  |  1991-06-14  |  2KB  |  89 lines

  1.  
  2. #include <stdio.h>
  3. #include <osfcn.h>
  4. #include <libc.h>
  5. #include <errno.h>
  6. #include <string.h>
  7. #include <netdb.h>
  8. #include <iostream.h>
  9.  
  10. #include "Transport.h"
  11.  
  12. #include <RJS/Util.h>
  13.  
  14. extern "C" {
  15.     unsigned long htonl(unsigned long);
  16.     unsigned short htons(unsigned short);
  17.     struct hostent *gethostbyname(const char *host);
  18. }
  19.  
  20. int RJS_InetSocket::connect(const RJS_InetAddress &ia)
  21. {
  22.     return RJS_Socket::connect(ia,ia.size());
  23. }
  24.  
  25. int RJS_InetSocket::bind(const RJS_InetAddress &ia)
  26. {
  27.     return RJS_Socket::bind(ia,ia.size());
  28. }
  29.  
  30. int RJS_InetSocket::getpeername(RJS_InetAddress &ia)
  31. {
  32.     ia.addrlen=ia.size();
  33.     int stat=RJS_Socket::getpeername(ia,ia.addrlen);
  34.     if (stat) ia.ss_set(RJS_InetAddress::HostFound);
  35.     else ia.ss_set(RJS_InetAddress::UnknownHost);
  36.     return stat;
  37. }
  38.  
  39. int RJS_InetSocket::getsockname(RJS_InetAddress &ia)
  40. {
  41.     ia.addrlen=ia.size();
  42.     int stat=RJS_Socket::getsockname(ia,ia.addrlen);
  43.     if (stat) ia.ss_set(RJS_InetAddress::HostFound);
  44.     else ia.ss_set(RJS_InetAddress::UnknownHost);
  45.     return stat;
  46. }
  47.  
  48. int RJS_InetSocket::accept(RJS_InetSocket &newsocket)
  49.  {
  50.      if (!ok() || !is_passive()) {
  51.          newsocket.td = -1; 
  52.         newsocket.ss_set(SS_error);
  53.         return 0; 
  54.     } 
  55.  
  56.     if (newsocket.inuse()) newsocket.close();
  57.  
  58.     newsocket = *this; // copy current socket
  59.     RJS_InetAddress remote;
  60.     remote.addrlen=remote.size();
  61.         newsocket.td = RJS_Socket::accept(remote,remote.addrlen);
  62.  
  63.     if (newsocket.td < 0 ) {
  64.         newsocket.ss_set(RJS_Status(errno));
  65.         if (return_on_error) return 0;
  66.         RJS_Util::crash_and_burn("RJS_InetSocket","accept",ss_message());
  67.     } else {
  68.         newsocket.ss_set(SS_success);
  69.         return 1;
  70.     }
  71.  
  72. }
  73.  
  74. int RJS_InetSocket::recvfrom(char *buffer,int maxbuf, RJS_InetAddress &ia)
  75. {
  76.     ia.addrlen=ia.size();
  77.     int stat=RJS_Socket::recvfrom(buffer,maxbuf,ia,ia.addrlen); 
  78.         if (stat) ia.ss_set(RJS_InetAddress::HostFound);
  79.     else ia.ss_set(RJS_InetAddress::NoHostGiven);
  80.     return stat;
  81. }
  82.  
  83. int RJS_InetSocket::sendto(char *buffer,int len,const RJS_InetAddress &ia)
  84. {
  85.     return RJS_Socket::sendto(buffer,len,ia,ia.addrlen); 
  86. }
  87.  
  88.  
  89.